from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5 import QtGui


import sys

class LineEditDemo(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(LineEditDemo, self).__init__(parent)

        self.setWindowTitle("LineEditdemo ")

        normalLineEdit = QtWidgets.QLineEdit()
        normalLineEdit.setPlaceholderText("normal")
        normalLineEdit.setEchoMode(QtWidgets.QLineEdit.Normal)

        noEchoLineEdit = QtWidgets.QLineEdit()
        noEchoLineEdit.setPlaceholderText("No Echo")
        noEchoLineEdit.setEchoMode(QtWidgets.QLineEdit.NoEcho)

        pswLineEdit = QtWidgets.QLineEdit()
        pswLineEdit.setPlaceholderText("password")
        pswLineEdit.setEchoMode(QtWidgets.QLineEdit.Password)

        pswEchoOnLineEdit = QtWidgets.QLineEdit()
        pswEchoOnLineEdit.setPlaceholderText("password echo on edit")
        pswEchoOnLineEdit.setEchoMode(QtWidgets.QLineEdit.PasswordEchoOnEdit)

        flo = QtWidgets.QFormLayout()
        flo.addRow("Normal", normalLineEdit)
        flo.addRow("NoEcho", noEchoLineEdit)
        flo.addRow("password", pswLineEdit)
        flo.addRow("password Echo On Edit", pswEchoOnLineEdit)

        self.setLayout(flo)

class LineEditDemo2(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(LineEditDemo2, self).__init__(parent)

        self.setWindowTitle("QLineEdit例子")

        intLineEdit = QtWidgets.QLineEdit()
        intValidator = QtGui.QIntValidator()
        intValidator.setRange(1, 99)
        intLineEdit.setValidator(intValidator)

        doubleLineEdit = QtWidgets.QLineEdit()
        doubleValidator = QtGui.QDoubleValidator()
        doubleValidator.setRange(-360, 360)
        doubleValidator.setNotation(QtGui.QDoubleValidator.StandardNotation)
        doubleValidator.setDecimals(6)
        doubleLineEdit.setValidator(doubleValidator)

        validatorLineEdit = QtWidgets.QLineEdit()
        reg = QtCore.QRegExp("[a-zA-Z0-9]+$")
        regValidator = QtGui.QRegExpValidator(self)
        regValidator.setRegExp(reg)
        validatorLineEdit.setValidator(regValidator)


        flo = QtWidgets.QFormLayout()
        flo.addRow("整数", intLineEdit)
        flo.addRow("浮点数", doubleLineEdit)
        flo.addRow("字母和数字", validatorLineEdit)

        self.setLayout(flo)

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    win = LineEditDemo2()
    win.show()
    sys.exit(app.exec_())